home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1998 November / Freeware November 1998.img / dist / fw_UDELxntp.idb / usr / freeware / src / xntp-3.4o-export / lib / numtohost.c.z / numtohost.c
C/C++ Source or Header  |  1998-01-21  |  859b  |  39 lines

  1. /*
  2.  * numtohost - convert network number to host name.
  3.  */
  4. #include <netdb.h>
  5.  
  6. #include "ntp_fp.h"
  7. #include "ntp_stdlib.h"
  8. #include "lib_strbuf.h"
  9.  
  10. #define    LOOPBACKNET    0x7f000000
  11. #define    LOOPBACKHOST    0x7f000001
  12. #define    LOOPBACKNETMASK    0xff000000
  13.  
  14. char *
  15. numtohost(netnum)
  16.     u_int32 netnum;
  17. {
  18.     char *bp;
  19.     struct hostent *hp;
  20.  
  21.     /*
  22.      * This is really gross, but saves lots of hanging looking for
  23.      * hostnames for the radio clocks.  Don't bother looking up
  24.      * addresses on the loopback network except for the loopback
  25.      * host itself.
  26.      */
  27.     if ((((ntohl(netnum) & LOOPBACKNETMASK) == LOOPBACKNET)
  28.         && (ntohl(netnum) != LOOPBACKHOST))
  29.         || ((hp = gethostbyaddr((char *)&netnum, sizeof netnum, AF_INET))
  30.           == 0))
  31.         return numtoa(netnum);
  32.     
  33.     LIB_GETBUF(bp);
  34.     
  35.     bp[LIB_BUFLENGTH-1] = '\0';
  36.     (void) strncpy(bp, hp->h_name, LIB_BUFLENGTH-1);
  37.     return bp;
  38. }
  39.